#!/bin/bash
#
# Init file for LuoYun node server daemon
#
# chkconfig: 2345 55 25
# description: LuoYun node server daemon
#
# processname: lyclc
# TOPDIR: /opt/LuoYun/platform/
# config: ${TOPDIR}/etc/luoyun-cloud/lyclc.conf
# pidfile: ${TOPDIR}/node_data/.lyclc.pid

# source function library
. /etc/rc.d/init.d/functions

LUOYUN_TOP_DIR=/opt/LuoYun/platform/
prog="lyclc"
LYCLCD="${LUOYUN_TOP_DIR}bin/lyclc"
OPTIONS="-d"
PID_FILE="/var/run/lyclc.pid"

runlevel=$(set -- $(runlevel); eval "echo \$$#" )


start()
{
    echo -n $"Starting $prog: "
    $LYCLCD $OPTIONS && success || failure
    RETVAL=$?
    [ "$RETVAL" = 0 ] && touch /var/lock/subsys/lyclc
    echo
}

stop()
{
    echo -n $"Stopping $prog: "
    if [ -n "`pidfileofproc $LYCLCD`" ] ; then
	killproc $LYCLCD
    else
	failure $"Stopping $prog"
    fi
    RETVAL=$?

    [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/lyclc
    echo
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	stop
	start
	;;
    status)
	status -p $PID_FILE lyclc
	RETVAL=$?
	;;
    *)
	echo $"Usage: $0 {start|stop|restart|status}"
	RETVAL=1
esac
exit $RETVAL
